const {
  Maybe,
  Container
} = require('./support');

const fp = require('lodash/fp');

//练习1-------------------------------start
let maybe = Maybe.of([5, 6, 1]);

let ext = y => {
  return maybe.map(value => {
    return fp.map(x => {
      return x = fp.add(x, y);
    }, value)
  });
}

// console.log(ext(4));
//练习1-------------------------------end

//练习2-------------------------------start
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do']);
let ex2 = () => {
  return xs.map(value => {
    return fp.map(x => {
      return fp.first(x);
    }, value);
  })._value;
}
// console.log(ex2());
//练习2-------------------------------end

//练习3-------------------------------start
let safeProp = fp.curry(function (x, o) {
  return Maybe.of(o[x]);
});

let user = {
  id: 2,
  name: 'Albert'
};
let ex3 = () => {
  return fp.first(safeProp('name', user)._value)
}
// console.log(ex3());
//练习3-------------------------------end

//练习4-------------------------------start
// let ex4 = function (n) {
//   if (n) {
//     return parseInt(n);
//   }
// }

let ex4 = function (n) {
  return Maybe.of(n).map(value => {
    return parseInt(value);
  })._value;
}
// console.log(ex4("12"));
//练习4-------------------------------end